<?php

    namespace App;

    use Illuminate\Contracts\Auth\MustVerifyEmail;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use Illuminate\Notifications\Notifiable;
    use Illuminate\Support\Facades\Auth;
    use Laravel\Passport\HasApiTokens;

    class User extends Authenticatable
    {
        use Notifiable, HasApiTokens;

        /**
         * The attributes that are mass assignable.
         *
         * @var array
         */
        protected $fillable
            = [
                'mobile','nick_name', 'email', 'password',
            ];

        /**
         * The attributes that should be hidden for arrays.
         *
         * @var array
         */
        protected $hidden
            = [
                'password', 'remember_token',
            ];

        /**
         * The attributes that should be cast to native types.
         *
         * @var array
         */
        protected $casts
                                 = [
                'email_verified_at' => 'datetime',
            ];
        public    $successStatus = 200;

        /**
         * 登录
         *
         * @return \Illuminate\Http\JsonResponse
         * login
         * author: walker
         * Date: 2019/11/11
         * Time: 18:51
         * Note:
         */
//        public function login()
//        {
//            if (Auth::attempt(['email' => request('email'), 'password' => request('password')])){
//                $user             = Auth::user();
//                $success['token'] = $user->createToken('test')->accessToken;
//                return response()->json(['success' => $success], $this->successStatus);
//            } else {
//                return response()->json(['error' => 'Unauthorised'], 401);
//            }
//        }

        /**
         * 注册用户
         * @param Request $request
         *
         * @return \Illuminate\Http\JsonResponse
         * register
         * author: walker
         * Date: 2019/11/19
         * Time: 10:43
         * Note:
         */
//        public function register(Request $request)
//        {
//            $validator = Validator::make($request->all(), [
//                'mobile'   => 'required',
//                'email'    => 'required|email',
//                'password' => 'required',
//
//            ]);
//
//            if ($validator->fails()){
//                return response()->json(['error' => $validator->errors()], 401);
//            }
//            $input             = $request->all();
//            $input['password'] = bcrypt($input['password']);
//            $user              = User::create($input);
//            $success['token']  = $user->createToken('test')->accessToken;
//            $success['name']   = $user->name;
//            return response()->json(['success' => $success], $this->successStatus);
//        }

//        public function details()
//        {
//            $user = Auth::user();
//            return response()->json(['success' => '授权成功'], $this->successStatus);
//        }
    }
